package com.zmx.job.admin.controller.handler;

import lombok.Data;
import org.springframework.http.HttpStatus;

/**
 * @Description: Controller异常的数据返回实体
 * @ClassName: ResponseResult
 * @Author zhaomxr
 * @Date 2021-10-09 16:13
 */
@Data
public class ResponseResult<T> {

    private int code;

    private String message;

    private T data;

    private long timestamp;

    public ResponseResult() {
        this.timestamp = System.currentTimeMillis();
    }

    public static <T> ResponseResult success(T data) {
        ResponseResult<T> responseResult = new ResponseResult<>();
        responseResult.setCode(HttpStatus.OK.value());
        responseResult.setData(data);
        return responseResult;
    }

    public static <T> ResponseResult success(String message, T data) {
        ResponseResult<T> responseResult = new ResponseResult<>();
        responseResult.setCode(HttpStatus.OK.value());
        responseResult.setMessage(message);
        responseResult.setData(data);
        return responseResult;
    }

    public static <T> ResponseResult fail(String message) {
        ResponseResult<T> responseResult = new ResponseResult<>();
        responseResult.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
        responseResult.setMessage(message);
        return responseResult;
    }
}
